package com.mindskip.xzs.utility.excel;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


/**
 * <p>
 * 针对JDK8的LocalDate类型，easyexcel默认的类型转换器是无法处理的，要自行编写转换器
 * </p>
 *
 * @author guoguangkai
 * @since 2022/1/25
 */

@Component
public class LocalDateTimeConverter implements Converter<LocalDateTime> {

    @Override
    public WriteCellData<LocalDate> convertToExcelData(LocalDateTime value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        return new WriteCellData<LocalDate>(value.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒")));
    }
}
